import json
import unittest
from utils.request_Util import request_Util


class APITestFlow(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        cls.header = {'Accept': 'application/json, text/plain, */*',
                      'Accept-Encoding': 'gzip, deflate',
                      'Accept-Language': 'zh-CN,zh;q=0.9',
                      'Connection': 'keep-alive',
                      'Content-Length': '0',
                      'Host': 'lianlianche.qicp.vip:9001',
                      'Origin': 'http://test-stwy.qingfengche.com',
                      'Referer': 'http://test-stwy.qingfengche.com/',
                      'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
                      }
        cls.request_util = request_Util(header=cls.header)

    # 登录接口，获取token等信息
    def test_Api01(self):
        url = 'http://lianlianche.qicp.vip:9001/freight/manage/login/tmsAuth'
        params = 'phone=18173378353&password=123456'
        res = self.request_util.post(url=url, params=params)
        result = res.json()
        assert result['msg'] == '登录成功'
        self.header['X-departmentId'] = result['data']['deptId']
        self.header['X-roleId'] = result['data']['roleId']
        self.header['X-Token'] = result['data']['token']
        self.header['X-uid'] = result['data']['uid']
        self.request_util.edit_header(self.header)

    # 获取当前用户信息
    def test_Api02(self):
        url = 'http://lianlianche.qicp.vip:9001/freight/manage/login/getInfo'
        res = self.request_util.get(url=url)
        print(res.text)
